﻿Imports System.Runtime.InteropServices
Imports System.Text.RegularExpressions
Imports System.Text

Public Class CommonMethod
    ''' <summary>
    ''' Bỏ dấu tiếng việt
    ''' </summary>
    ''' <param name="pString"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    <ComVisible(True)>
    Public Function TrimAccentedString(pString As String) As String
        Dim v_reg_regex As New Regex("\p{IsCombiningDiacriticalMarks}+")
        Dim v_str_FormD As String = pString.Normalize(NormalizationForm.FormD)
        Return v_reg_regex.Replace(v_str_FormD, [String].Empty).Replace("đ"c, "d"c).Replace("Đ"c, "D"c)
    End Function

    ''' <summary>
    ''' Thay thế các khoảng trắng liên tiếp thành 1 khoảng trắng
    ''' </summary>
    ''' <param name="pString"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    <ComVisible(True)>
    Public Function TrimMultiWhiteSpace(pString As String) As String
        Dim regex As New Regex("\s+")
        Return regex.Replace(pString, " ")
    End Function

    ''' <summary>
    ''' Lọc bỏ các ký tự không phải là chữ số
    ''' </summary>
    ''' <param name="pString"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    <ComVisible(True)>
    Public Function TrimNonAlphaNumeric(pString As String) As String
        Dim regex As New Regex("[^a-zA-Z0-9 ]")
        Return regex.Replace(pString, "")
    End Function
End Class
